package com.rmt.www.daoImpl;

import java.util.List;

import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

import com.rmt.www.dao.FeatureArtifactRequestDao;
import com.rmt.www.vo.FeatureArtifactRequest;
import com.rmt.www.vo.TestArtifactRequest;

public class FeatureArtifactRequestDaoImpl implements FeatureArtifactRequestDao {
	private JdbcTemplate jdbcTemplate;

	public void setDataSource(DataSource dataSource) {
		this.jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	public void deleteFeatureArtifactRequestById(int id) {
		this.jdbcTemplate.update("update featureartifactrequest set status='deleted' where id=?", new Object[]{id}, new int[]{java.sql.Types.INTEGER});
	}

	public FeatureArtifactRequest getFeatureArtifactRequestById(int id) {
		return (FeatureArtifactRequest) this.jdbcTemplate.queryForObject("select* from featureartifactrequest where id=? and status!='deleted'", 
				new Object[]{id}, new FeatureArtifactRequestRowMapper());
	}

	@SuppressWarnings("unchecked")
	public List<FeatureArtifactRequest> getFeatureArtifactRequestsByPId(int pid) {
		return this.jdbcTemplate.query("select * from featureartifactrequest where pid=? and status!='deleted'", 
				new Object[]{pid}, new int[]{java.sql.Types.INTEGER}, new FeatureArtifactRequestRowMapper());
	}

	public void insertFeatureArtifactRequest(FeatureArtifactRequest newRequest) {
		jdbcTemplate.update("insert into featureartifactrequest(pid,title,authorid,version,priority,source,rational,createdtime,updaterid,updatedtime,status,description,cost,effort,risk,updatedtimes,featureartifactid,requesttype) " +
				"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", 
		new Object[]{
			newRequest.getPid(),
			newRequest.getTitle(),
			newRequest.getAuthorId(),
			newRequest.getVersion(),
			newRequest.getPriority(),
			newRequest.getSource(),
			newRequest.getRational(),
			newRequest.getCreatedtime(),
			newRequest.getUpdateUserId(),
			newRequest.getUpdatedtime(),
			newRequest.getStatus(),
			newRequest.getDescription(),
			newRequest.getCost(),
			newRequest.getEffort(),
			newRequest.getRisk(),
			newRequest.getUpdatedtimes(),
			newRequest.getFeatureartifactid(),
			newRequest.getRequesttype()
		},new int[] {
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR,
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.TIMESTAMP,
				java.sql.Types.INTEGER,
				java.sql.Types.TIMESTAMP,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.VARCHAR,
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR,
				java.sql.Types.INTEGER,
				java.sql.Types.INTEGER,
				java.sql.Types.VARCHAR
		});
	}

	
}
